import event from '../../../utils/event.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    language: '',
    languages: ['简体中文', 'English'],
    langIndex: 0
  },

  onLoad: function () {
    
    this.setData({
      langIndex: wx.getStorageSync('langIndex')
    });
    this.setLanguage();
    // ...
  },

  changeLanguage(e) {
    
    let index = e.currentTarget.dataset.value;
    this.setData({	// (1)
      langIndex: index
    });
    wx.T.setLocaleByIndex(index);
    this.setLanguage();
    event.on('languageChanged');

    wx.setStorage({
      key: 'langIndex',
      data: this.data.langIndex
    })
  },

  setLanguage() {
    this.setData({
      language: wx.T.getLanguage()
    });
  }
})